package ch.ffhs.activities;

import ch.ffhs.services.ServiceManager;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

/**
 * class AlarmActivity. Displays an alarm and a list of emergency-contacts with
 * the state of message-sending.
 * 
 * @author mf
 */
public class AlarmActivity extends Activity {
	private ServiceManager serviceManager = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_alarm);

		if (ServiceManager.currentServiceManager != null) {
			serviceManager = ServiceManager.currentServiceManager;

			ListView contactsList = (ListView) findViewById(R.id.listAlarmContacts);
			contactsList.setAdapter(serviceManager.contactAlarmListAdapter);
		}
	}

	public void onClickAlarmStop(final View sfNormal) {
		// set result
		this.setResult(RESULT_OK);

		// remove notification
		AlarmNotification
				.clearNotification(AlarmNotification.ALARM_NOTIFICATION);

		// closing alarm activity
		finish();
	}

	@Override
	public void onBackPressed() {
		// set result
		this.setResult(RESULT_OK);

		// remove notification
		AlarmNotification
				.clearNotification(AlarmNotification.ALARM_NOTIFICATION);

		super.onBackPressed();
	}
}
